﻿using System;
using System.Collections.Generic;
using System.Text;
using LLFM.CAT.Config;
using Common;
using System.Data;
using System.Data.SqlClient;
using LLFM.CAT.Model;

namespace LLFM.CAT.Service
{
    public sealed class FocusImagesService
    {
        /// <summary>
        /// 得到单个焦点图
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static M_FocusImages GetFocusImagesById(int id)
        {
            DataTable dt = SqlHelper.ExecuteDataset(DBConfig.BitautoSDT
                , CommandType.StoredProcedure
                , "pro_GetFocusImagesById"
                , new SqlParameter("@Id", id)).Tables[0];

            return ModelHelper.FillModel<M_FocusImages>(dt);
        }


        /// <summary>
        /// 读取焦点图列表
        /// </summary>
        /// <param name="status"></param>
        /// <returns></returns>
        public static List<M_FocusImages> GetFocusImagesList(int status)
        {
            DataTable dt = SqlHelper.ExecuteDataset(DBConfig.BitautoSDT
                , CommandType.StoredProcedure
                , "pro_GetFocusImagesList"
                , new SqlParameter("@Status", status)).Tables[0];
            return ModelHelper.FillModelsFromDataTable<M_FocusImages>(dt);
        }


        /// <summary>
        /// 创建焦点图
        /// </summary>
        /// <param name="imageUrl"></param>
        /// <param name="name"></param>
        /// <param name="createTime"></param>
        /// <param name="status"></param>
        /// <param name="lastUpdateTime"></param>
        /// <param name="sequence"></param>
        public static void CreateFocusImages(string imageUrl
            , string name
            , DateTime createTime
            , int status
            , DateTime lastUpdateTime
            , int sequence)
        {
            SqlHelper.ExecuteNonQuery(DBConfig.BitautoSDT
                , CommandType.StoredProcedure
                , "pro_CreateFocusImages"
                , new SqlParameter("@ImageUrl", imageUrl)
                , new SqlParameter("@Name", name)
                , new SqlParameter("@CreateTime", createTime)
                , new SqlParameter("@Status", status)
                , new SqlParameter("@LastUpdateTime", lastUpdateTime)
                , new SqlParameter("@Sequence", sequence));
        }


        /// <summary>
        /// 修改焦点图
        /// </summary>
        /// <param name="imageUrl"></param>
        /// <param name="name"></param>
        /// <param name="createTime"></param>
        /// <param name="status"></param>
        /// <param name="lastUpdateTime"></param>
        /// <param name="sequence"></param>
        public static void UpdateFocusImagesById(int id
            , string imageUrl
            , string name
            , DateTime createTime
            , int status
            , DateTime lastUpdateTime
            , int sequence)
        {
            SqlHelper.ExecuteNonQuery(DBConfig.BitautoSDT
                , CommandType.StoredProcedure
                , "pro_UpdateFocusImagesById"
                , new SqlParameter("@Id", id)
                , new SqlParameter("@ImageUrl", imageUrl)
                , new SqlParameter("@Name", name)
                , new SqlParameter("@CreateTime", createTime)
                , new SqlParameter("@Status", status)
                , new SqlParameter("@LastUpdateTime", lastUpdateTime)
                , new SqlParameter("@Sequence", sequence));
        }
    }
}
